package thread;

public class ThreadJoin {
    private static long sum = 0;
    public static void main(String[] args) throws InterruptedException {
        Thread t =new Thread(()->{
            long ret = 0;
            for (long i = 1; i <= 10_0000_0000L ; i++) {
                ret += i;
            }
            sum += ret;
        });
        Thread t2 =new Thread(()->{
            long ret = 0;
            for (long i = 10_0000_0001L; i <= 20_0000_0000L ; i++) {
                ret += i;
            }
            sum += ret;
        });
        t.start();
        t2.start();
        long beg = System.currentTimeMillis();
        //阻塞线程
        t.join();//死等
//        t.join(1000);有上限时间的等待 (ms)
//        t.join(1000,1000);(ms,ns)
        t2.join();
        long end = System.currentTimeMillis();
        System.out.println("sum= "+sum);
        System.out.println("time= "+(end - beg)+"ms");
    }
}
